#include "stdafx.h"
#include "User.h"
#include "UserManager.h"
#include "PatchServer.h"
#include "Packet.h"
#include "PacketCreator.h"
#include "PacketFactory.h"

Packet* PacketCreator::HelloCommand()
{
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	*pSendMsg<<(uint32)0x28;
	*pSendMsg<<(uint32)1;
	*pSendMsg<<(uint32)0xfa2d9f8b;//0x8b9f2dfa
	*pSendMsg<<(uint32)0;
	*pSendMsg<<(uint32)0;
	*pSendMsg<<(uint32)0;
	*pSendMsg<<(uint32)1;
	*pSendMsg<<(uint32)0;
	*pSendMsg<<(uint32)0;
	*pSendMsg<<(uint32)0;
	return pSendMsg;
}

Packet* PacketCreator::ChangeFolderCommand(char* pFolderName)
{   
	Binary NameBin(pFolderName,strlen(pFolderName),64-strlen(pFolderName));
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	*pSendMsg<<(uint32)0x48;
	*pSendMsg<<(uint32)0x09;
	*pSendMsg<<NameBin;
	return pSendMsg;
}

Packet* PacketCreator::BackToRootFolderCommand()
{
    
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	*pSendMsg<<(uint32)0x08;
	*pSendMsg<<(uint32)0x0a;
	return pSendMsg;
}

Packet* PacketCreator::GeneralUpdateInformationCommand()
{   
	
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	uint32 size = 0;
	uint32 NbFiles = 0;
	*pSendMsg<<(uint32)0x10;
	*pSendMsg<<(uint32)0x0f;
	*pSendMsg<<size;
	*pSendMsg<<NbFiles;
	return pSendMsg;
   
}

Packet* PacketCreator::FileUpdateBeginCommand()
{

	Binary NameBin("",strlen(""),64-strlen(""));
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	uint32 size = 0;
	uint32 NbFiles = 0;
	*pSendMsg<<(uint32)0x50;
	*pSendMsg<<(uint32)0x10;
	*pSendMsg<<(uint32)0;
	*pSendMsg<<size;
	*pSendMsg<<NameBin;
	return pSendMsg;
}

Packet* PacketCreator::SendAFileFragmentCommand()
{
   
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	uint32 DataSize = 4;
	uint32 size = DataSize+0x14;
	uint32 N = 0;
	uint32 CRC32 = 0;
	*pSendMsg<<(uint32)size;
	*pSendMsg<<(uint32)0x11;
	*pSendMsg<<N;
	*pSendMsg<<CRC32;
	*pSendMsg<<DataSize;
	//*pSendMsg<<DataBin;
	return pSendMsg;
}

Packet* PacketCreator::FileUpdateEndCommand()
{

	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	*pSendMsg<<(uint32)8;
	*pSendMsg<<(uint32)0x12;
	return pSendMsg;

}

Packet* PacketCreator::UpdateCompleteCommand()
{
	Packet *pSendMsg = PacketFactory::Instance()->Alloc();
	*pSendMsg<<(uint32)8;
	*pSendMsg<<(uint32)0x13;
	return pSendMsg;
}